package net.fdukedom.epicurus.presentation.actions.pub;

import net.fdukedom.epicurus.presentation.actions.AbstractAction;
import net.fdukedom.epicurus.presentation.SessionData;
import net.fdukedom.epicurus.domain.util.UserHelper;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Login action.
 * 
 * @author Dmitry Y. Kochelaev
 */
public class LoginAction extends AbstractAction<LoginForm> {

    private UserHelper userHelper = UserHelper.getInstance();

    protected ActionForward doExecute(ActionMapping mapping, LoginForm form, HttpServletRequest request, HttpServletResponse response) {
        SessionData sessionData = SessionData.getInstance(request);
        sessionData.setUser(userHelper.findByEmail(form.getEmail()));
        return mapping.findForward("success");
    }
}
